package service.impl;

import dao.CatgoryMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import pojo.Category;
import pojo.Page;
import service.CatgoryService;

import javax.annotation.Resource;
import java.awt.print.Book;
import java.util.List;

/**
 * @ClassName 刘星宇
 * @Description TODO
 * @date 2022/11/25 14:11
 * @Version 1.0
 */
@Service
public class CatgoryServiceImpl implements CatgoryService {
    @Resource
    private CatgoryMapper catgoryMapper;
    @Override
    public List<Category> getCatAll() {
        List<Category> list = catgoryMapper.getCatAll();
        return list;
    }
    //分页
    @Override
    public Page<Category> getCatAllByPage(Page<Category> page) {
        Page<Category> Catpage =new Page<>();
        //设置当前页
        Catpage.setCurrentPage(page.getCurrentPage());
        //设置每页条数
        Catpage.setPageSize(page.getPageSize());
        //设置每页数据
        Catpage.setLists(catgoryMapper.getCatAllByPage(page));
        //设置总条数
        Catpage.setTotalRecord(catgoryMapper.getCategoryCount());
        return Catpage;
    }
    //新增&修改
    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public int addOrUpCategory(Category category) {
        int i =0;
        if (category.getCategoryID()!=0){
            i=catgoryMapper.getCatUpdate(category);
        }else {
            i=catgoryMapper.getCatAdd(category);
        }
        return i;
    }
    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public int getCatDel(Category category) {
        int i = catgoryMapper.getCatDel(category);
        return i;
    }
}
